<?php 

class Image_model extends CI_Model {

	function __construct(){
		parent::__construct();
		$this->load->database();
	}

	public function insert($news, $preview, $id, $type){
		
		$query = $this->db->insert('img', array('img' => addslashes($news), 'preview' => addslashes($preview), 'p_id' => $id, 'type' => $type, 'datetime' => date("Y-m-d H:i:s")));
		return $this->db->affected_rows();
	}

	public function get_item(){
		$query = $this->db->get("img");
		return $query->result_array();
	}

	public function del($id){
		$this->db->delete("img", array('id' => $id));
		return $this->db->affected_rows();
	}

	public function getbypid($p_id){
		$this->db->where('p_id', $p_id);
		$this->db->order_by('id', 'desc');
		$query = $this->db->get("img");
		return $query->result_array();
	}
}